package com.ysstech.common.util;


/*import com.spire.doc.Document;
import com.spire.doc.Table;
import com.spire.doc.TableCell;
import com.spire.doc.TableRow;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.TextBox;
import com.spire.pdf.PdfDocument;
import com.spire.pdf.utilities.PdfTable;
import com.spire.pdf.utilities.PdfTableExtractor;*/
import org.apache.poi.ss.usermodel.Workbook;

import java.io.FileWriter;
import java.io.IOException;

public class ExtractTable {


    public static void main(String[] args) throws IOException {
        ExtractTable.readDocTable();
    }

    private static void readDbfTable() {
       /* //加载PDF文档
        PdfDocument pdf = new PdfDocument();
        pdf.loadFromFile("C:\\Users\\zijin\\Desktop\\报表世界\\证监会\\附件2：证券基金经营机构资产管理产品数据报送接口规范.pdf");
        //创建StringBuilder类的实例
        StringBuilder builder = new StringBuilder();
        //抽取表格
        PdfTableExtractor extractor = new PdfTableExtractor(pdf);
        PdfTable[] tableLists;
        for (int page = 0; page < pdf.getPages().getCount(); page++) {
            tableLists = extractor.extractTable(page);
            if (null == tableLists || tableLists.length == 0) {
                continue;
            }
            for (PdfTable table : tableLists) {
                int row = table.getRowCount();
                int column = table.getColumnCount();
                for (int i = 0; i < row; i++) {
                    for (int j = 0; j < column; j++) {
                        String text = table.getText(i, j);
                        builder.append(text + " ");
                    }
                    builder.append("\r\n");
                }
            }
        }
        System.out.println(builder);*/
        //将提取的表格内容写入txt文档
       /* FileWriter fileWriter = new FileWriter("E:\\文档\\金融数据抽取\\公告\\600519_贵州茅台_贵州茅台2019年年度报告.txt");
        fileWriter.write(builder.toString());
        fileWriter.flush();
        fileWriter.close();*/
    }

    private static void readDocTable() {
        //加载PDF文档
      /*  Document doc = new Document();
        doc.loadFromFile("C:\\Users\\zijin\\Desktop\\报表世界\\证监会\\附件1：证券基金经营机构公募证券投资基金数据报送接口规范(1).docx");
        //创建StringBuilder类的实例
        StringBuilder builder = new StringBuilder();
        //获取文本框中第一个表格
        TextBox textbox = doc.getTextBoxes().get(0);
        Table table = textbox.getBody().getTables().get(0);
        //遍历表格中的段落并提取文本
        for (int i = 0; i < table.getRows().getCount(); i++) {
            TableRow row = table.getRows().get(i);
            for (int j = 0; j < row.getCells().getCount(); j++) {
                TableCell cell = row.getCells().get(j);
                for (int k = 0; k < cell.getParagraphs().getCount(); k++) {
                    Paragraph paragraph = cell.getParagraphs().get(k);
                    System.out.println(paragraph.getText() + "\t");
                }
            }
        }*/
    }
}
